import request from '@/utils/request';

const API = {
    // 请假放行记录
    LEAVE_NOTE_URL: '/v1/biz/leaves/save',
    // 请假条已办记录
    LEAVE_PROCCESSED_URL: '/v1/biz/leaves/all',
    // 请假记录和放行记录查询
    INQUIRE_LEAVE_NOTE_URL: '/v1/biz/leaves/all',
    // 通过id获取请假条具体内容
    GET_LEAVE_DETAIL_BY_ID_URL: '/v1/biz/leaves/one',
    // 老师通过请假条
    PASS_LEAVE_URL: '/v1/biz/leaves/save',
    // 获取请假条图片证明
    GET_PICTURE_IN_NOTE: '/biz/Files/picture'
};

// 请假放行记录
export const reqLeaveNote = (pageNo, pageSize = 5) =>
    request.get(`${API.LEAVE_NOTE_URL}?pageNo=${pageNo}&pageSize=${pageSize}`);

// 请假条已办记录
export const reqLeaveProccessed = (pageNo, pageSize, stateStr) =>
    request.get(
        `${API.LEAVE_PROCCESSED_URL}?pageNo=${pageNo}&pageSize=${pageSize}&${stateStr}`
    );

// 查询请假和放行记录
export const reqInquireLeaveNote = (
    pageNo,
    pageSize,
    states,
    createTimeStart,
    createTimeEnd,
    department
) =>
    request.get(
        `${API.INQUIRE_LEAVE_NOTE_URL}?pageNo=${pageNo}&pageSize=${pageSize}&states=${states}&createTimeStart=${createTimeStart}&createTimeEnd=${createTimeEnd}&keyword=${department}&leaveTypes=1&leaveTypes=2&leaveTypes=3`
    );

// 通过id获取请假条具体内容
export const reqLeaveDetail = id =>
    request.get(`${API.GET_LEAVE_DETAIL_BY_ID_URL}/${id}/`);

// 老师通过请假条
export const reqPassLeaveNote = data => request.put(API.PASS_LEAVE_URL, data);

// 获取请假条图片证明
export const reqImgInNote = id =>
    request({
        url: `${API.GET_PICTURE_IN_NOTE}?id=${id}`,
        method: 'get',
        responseType: 'blob'
    });
